<template>
  <el-select 
    v-model="initValue"
    placeholder="Select"
    v-bind="$attrs"
    @change="$emit('update:value', initValue)"
  >
    <el-option
      v-for="item in options"
      :key="item.key"
      :label="item.value"
      :value="item.key"
    />
  </el-select>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { useDictStore } from '@/store/dict';

const store = useDictStore();

const props = defineProps({
  value: { type: String, default: '' },
  url: { type: String, default: '' }
});

const initValue = ref(props.value);
const options = ref([]);

//  异步加载数据
store.dictData(props.url).then(res => {
  options.value = res.data;
})

</script>
